var ClubDisbandSettingWindow = Window.extend({
    _ccsFileName: res.ClubDisbandSettingWindow_json,

    _disBandType: 1, //解散类型 1、全部同意(默认)  2、超过一半  3、不可解散
    _disBanedTime: 60, //解散房间等待时间 默认60秒
    _jieSanTime: 180,    //未满桌子解散时间 默认180秒

    //根据选择的世界类型 转换得到 对应的秒数
    _checkDown2Time: [60, 180, 300],
    //未满桌子解散时间
    _checkJieSanTime: [180, 300, 600, 9999999],
    _clubId: null,
    initWindow: function (clubId) {
        this._clubId = clubId;

        var disBandType = 0;
        var disBandTime = 0;
        var jieSanTime = 0;
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo && clubInfo['param'] && clubInfo['param']['disBandSetting']) {
            var arr = clubInfo['param']['disBandSetting'].split(',');
            disBandType = parseInt(arr[0]) - 1;
            disBandTime = this._checkDown2Time.indexOf(parseInt(arr[1]));
            jieSanTime = this._checkJieSanTime.indexOf(parseInt(arr[2]));
            jieSanTime = jieSanTime < 0 ? 0 : jieSanTime
        }
        this._clickUpCheckBox({index: disBandType});
        this._clickDownCheckBox({index: disBandTime});
        this._clickJieSan({index: jieSanTime});
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_ok': '_clickOk'
        };
        for (var i = 0; i < 3; i++) {
            this._nodeList['checkBox_up_' + i].index = i;
            this._nodeList['checkBox_up_' + i + '.label'].index = i;

            this._nodeList['checkBox_down_' + i].index = i;
            this._nodeList['checkBox_down_' + i + '.label'].index = i;

            this._clickListeners['checkBox_up_' + i] = '_clickUpCheckBox';
            this._clickListeners['checkBox_up_' + i + '.label'] = '_clickUpCheckBox';
            this._clickListeners['checkBox_down_' + i] = '_clickDownCheckBox';
            this._clickListeners['checkBox_down_' + i + '.label'] = '_clickDownCheckBox';
        }

        for (var i = 0; i < 4; i++) {
            this._nodeList['checkBox_jiesan' + i].index = i;
            this._nodeList['checkBox_jiesan' + i + '.label'].index = i;
            this._clickListeners['checkBox_jiesan' + i] = '_clickJieSan';
            this._clickListeners['checkBox_jiesan' + i + '.label'] = '_clickJieSan';
        }
    },

    _clickUpCheckBox: function (target) {
        var index = target.index;
        for (var i = 0; i < 3; i++) {
            var unselect_color = cc.color("#7a5535");
            var select_color = cc.color("#15b62c");
            this._nodeList['checkBox_up_' + i + '.label'].setTextColor((i == index ? select_color : unselect_color));
            this._nodeList['checkBox_up_' + i + '.select'].setVisible((i == index));
        }
        //解散类型
        this._disBandType = (index + 1);
    },

    _clickDownCheckBox: function (target) {
        var index = target.index;
        for (var i = 0; i < 3; i++) {
            var unselect_color = cc.color("#7a5535");
            var select_color = cc.color("#15b62c");
            this._nodeList['checkBox_down_' + i + '.label'].setTextColor((i == index ? select_color : unselect_color));
            this._nodeList['checkBox_down_' + i + '.select'].setVisible((i == index));
        }
        this._disBanedTime = this._checkDown2Time[index];
    },

    _clickJieSan: function (target) {
        var index = target.index;
        for (var i = 0; i < 4; i++) {
            var unselect_color = cc.color("#7a5535");
            var select_color = cc.color("#15b62c");
            this._nodeList['checkBox_jiesan' + i + '.label'].setTextColor((i == index ? select_color : unselect_color));
            this._nodeList['checkBox_jiesan' + i + '.select'].setVisible((i == index));
        }
        this._jieSanTime = this._checkJieSanTime[index];
    },

    _clickOk: function () {
        var value = this._disBandType + ',' + this._disBanedTime + ',' + this._jieSanTime;
        network.send(2103, {
            cmd: 'ClubParamSet',
            key: 'disBandSetting',
            value: value,
            club_id: this._clubId
        });
        this.close();
    },
});